home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / GraKa / VLRecNG / Inst / VLRec_NG / StarGate / Developers / StarGateExample.c < prev   
C/C++ Source or Header  |  1999-12-18  |  4KB  |  138 lines

  1. /* StarGateExample 1.0
  2.    (c) 1999 by Felix Schwarz (felix@innovative-web.de).
  3.    All rights reserved.
  4.    This sourcecode is placed in the Public Domain:
  5.     Use it for whatever you want, but don`t make
  6.     me responsible, if anything doesn`t work as
  7.     it should. This sourcecode is supplied "as is"
  8.     and I cannot be held responsible, if it causes
  9.     any damages and/or errors, loss of money, health
  10.     or whatever. Use it fully at your own risk.
  11.  
  12.    The StarGate Plugin may be included into an archive
  13.    with previous permission by Felix Schwarz. Drop me
  14.    (felix@innovative-web.de) a mail and ask for a free
  15.    license.
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #include <exec/ports.h>
  22. #include <clib/exec_protos.h>
  23. #include "stargate.h"
  24.  
  25. struct fsbitmap
  26. {
  27.         APTR location;   // Pointer to the RGB-data
  28.         long width;      // width of the image to transmit
  29.         long height;     // height of the image to transmit
  30.         long type;       // Set this to 3
  31. };
  32.  
  33. // Send an image to fxPAINT without saving it inbetween
  34. BOOL sendimg_to_stargate(struct fsbitmap *fsb)
  35. {
  36.         struct SGMessage msg;
  37.         struct Message *reply;
  38.         struct MsgPort *ReplyPort;
  39.         struct MsgPort *SGPort;
  40.         BOOL ok=FALSE;
  41.  
  42.         if (ReplyPort=CreateMsgPort())
  43.         {
  44.                 Forbid();
  45.                 if (SGPort=FindPort("Stargate Airport"))
  46.                 {
  47.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  48.                         msg.msg.mn_Length       = sizeof(struct SGMessage);
  49.                         msg.msg.mn_ReplyPort    = ReplyPort;
  50.                         msg.fsb                 = fsb;
  51.  
  52.                         PutMsg(SGPort, (struct Message *) &msg);
  53.                 }
  54.                 Permit();
  55.  
  56.                 if (SGPort)
  57.                 {
  58.                         Wait(1L << ReplyPort->mp_SigBit);
  59.                         reply=GetMsg(ReplyPort);
  60.                         ok=TRUE;
  61.                 }
  62.                 else
  63.                 {
  64.                         // Give out this (or similiar) error message here:
  65.                         // "Stargate not found or fxPAINT not started"
  66.                 }
  67.  
  68.                 DeleteMsgPort(ReplyPort);
  69.         }
  70.  
  71.         return(ok);
  72. }
  73.  
  74. // Send a filename to fxPAINT in order to fxPAINT loading that file
  75. BOOL sendfile_to_stargate (char *file)
  76. {
  77.         struct SGMessageExt msg;
  78.         struct Message *reply;
  79.         struct MsgPort *ReplyPort;
  80.         struct MsgPort *SGPort;
  81.         BOOL ok=FALSE;
  82.  
  83.         if (ReplyPort=CreateMsgPort())
  84.         {
  85.                 Forbid();
  86.                 if (SGPort=FindPort("Stargate Airport"))
  87.                 {
  88.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  89.                         msg.msg.mn_Length       = sizeof(struct SGMessageExt);
  90.                         msg.msg.mn_ReplyPort    = ReplyPort;
  91.                         msg.type                = SG_LOAD_IMAGE;
  92.                         msg.data                = (APTR) file;
  93.  
  94.                         PutMsg(SGPort, (struct Message *) &msg);
  95.                 }
  96.                 Permit();
  97.  
  98.                 if (SGPort)
  99.                 {
  100.                         Wait(1L << ReplyPort->mp_SigBit);
  101.                         reply=GetMsg(ReplyPort);
  102.                         ok=TRUE;
  103.                 }
  104.                 else
  105.                 {
  106.                         // Give out this (or similiar) error message here:
  107.                         // "Stargate not found or fxPAINT not started"
  108.                 }
  109.  
  110.                 DeleteMsgPort(ReplyPort);
  111.         }
  112.  
  113.         return(ok);
  114. }
  115.  
  116. void main(int argc, char *argv[])
  117. {
  118.         if (argc > 1)
  119.         {
  120.                 printf("Sending %s to fxPAINT ..\n",argv[1]);
  121.                 if (sendfile_to_stargate(argv[1]))
  122.                 {
  123.                         printf(".. sent!\n");
  124.                         exit(0);
  125.                 }
  126.                 else
  127.                 {
  128.                         printf("Stargate not found or fxPAINT not running ..\n");
  129.                         exit(5);
  130.                 }
  131.         }
  132.         else
  133.         {
  134.                 printf("Usage: StarGateExample [file]\n");
  135.                 exit(5);
  136.         }
  137. }
  138.